package integration;

import java.sql.*;
import javax.sql.DataSource;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.util.Properties;

import javax.naming.*;
import metier.UserBean;



public class UserDAO {
	
	
	//fichiers properties : name = string_sql ; bundle
	private static Properties orders = new Properties();
	
	static{
		FileReader fr;
		try {
			fr = new FileReader("orders.sql");
			orders.load(fr);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}


	public void insert(UserBean bean)
	{
		try
		{
			InitialContext context = new InitialContext();
			//chaine jndi
			DataSource ds = (DataSource)context.lookup("jdbc/ds");
			Connection conX = ds.getConnection();
			String insertSQL = orders.getProperty("insertUser");
			PreparedStatement pstnt = conX.prepareStatement(insertSQL);
			pstnt.setString(1,bean.getNom());
			pstnt.setString(2,bean.getPrenom());
			pstnt.execute();
		}
		catch(Exception e){};
	}
}
